package com.fanbuchi.demo.fresco;

import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

import com.facebook.drawee.view.SimpleDraweeView;


public class MainActivity extends ActionBarActivity implements View.OnClickListener,RadioGroup.OnCheckedChangeListener{
    SimpleDraweeView draweeView;
    Button button;
    RadioGroup radio;
    Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/fresco-logo.png");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        draweeView=(SimpleDraweeView)findViewById(R.id.image);
        button=(Button)findViewById(R.id.button);
        button.setOnClickListener(this);
        radio=(RadioGroup)findViewById(R.id.radio);
        radio.setOnCheckedChangeListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View view) {
    switch (view.getId()){
        case R.id.button:

            draweeView.setImageURI(uri);
            break;
    }
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
    switch (i){
        case R.id.radio1:
            uri=Uri.parse("http://d.hiphotos.baidu.com/image/pic/item/fc1f4134970a304e6636e500d2c8a786c9175c37.jpg");
            break;
        case R.id.radio2:
            uri=Uri.parse("http://e.hiphotos.baidu.com/image/pic/item/aa64034f78f0f736335d21960955b319eac41381.jpg");
            break;
        case R.id.radio3:
            uri=Uri.parse("http://f.hiphotos.baidu.com/image/pic/item/a9d3fd1f4134970afd3bc36697cad1c8a7865d2b.jpg");
            break;
        case R.id.radio4:
            uri=Uri.parse("http://d.hiphotos.baidu.com/image/pic/item/a50f4bfbfbedab64909f27cef536afc378311eca.jpg");
            break;

    }
    }
}
